<template>
	<view class="parent-view">
		<view class="card-info-view">
			<view class="top-info">
				<view class="head-view">
					<image class="head-image" :src="userData.avatar"></image>
					<text class="name-txt">{{userData.nickname+userData.nickcname}}</text>
				</view>
				<view class="jpg-info-view">
					<view class="jpg-name-view">
						<text class="jpg-name">{{jiapuguanData.name}} ID:{{jiapuguanData.code}}</text>
						<text class="jpg-change" @click="changeGM">切换</text>
					</view>
					<text class="jpg-address">{{jiapuguanData.ance}}</text>
					<text class="jpg-time">开通时间：{{jiapuguanData.createtime}}</text>
				</view>
			</view>
			<view class="yye-txt-view">
				<text class="yye-txt">营业额：{{jiapuguanData.price}}</text>
				<text class="open-gdb" @click="openMerit">开通功德榜</text>
			</view>
		</view>
		<view class="tabbar-view">
			<text class="tabbar-item" :style="tabIndex==0?'color: #FF4206;':'color: #000000;'" @click="tabClick" :data-current="0">营业额明细</text>
			<text class="tabbar-item" :style="tabIndex==1?'color: #FF4206;':'color: #000000;'" @click="tabClick" :data-current="1">家谱管理</text>
			<text class="tabbar-item" :style="tabIndex==2?'color: #FF4206;':'color: #000000;'" @click="tabClick" :data-current="2">修谱师管理</text>
		</view>
		<view class="list-parent">
			<swiper :current="tabIndex" @change="ontabchange" class="swiper-box" :indicator-dots="false" :vertical="false">
				<swiper-item class="swiper-item" v-for="index in 3" :key="index">
					<scroll-view class="sv-view" scroll-y="true" :show-scrollbar="false" @scrolltolower="onreachBottom">
						<view class="swiper-item-view">
							<!-- 营业额明细 -->
							<view v-if="tabIndex==0" class="yye-view" v-for="(item , index) in yyeList" :key="index">
								<view class="yye-name-view">
									<text class="yye-name-tag"></text>
									<text class="yye-name-txt">{{item.uname}} {{item.umobile}}</text>
									<text class="yye-price">+{{item.price}}</text>
								</view>
								<text class="yye-jiapu-name">{{item.treename}} ({{item.treecode}})</text>
								<view class="yye-jiapu-xiupushi">
									<text class="yye-jiapu-xiupushi-name" v-if="item.rname">修谱师：{{item.rname}} {{item.rmobile}}</text>
									<text class="yye-jiapu-xiupushi-fenpei" v-else @click="fenpeiXPS1"  :data-index="item">分配修谱师</text>
								</view>
								<text class="yye-order-num">订单编号：{{item.ordersn}}</text>
								<text class="yye-order-time">付款时间：{{item.pay_time}}</text>
								<text class="yye-order-beizhu">订单备注：{{item.bio}}</text>
							</view>
							<!-- 家谱管理 -->
							<view v-if="tabIndex==1" class="jpm-view" v-for="(item , index) in jpmList" :key="index">
								<view class="jpm-jiapu-name-view">
									<text class="jpm-jiapu-name-tag"></text>
									<text class="jpm-jiapu-name">{{item.title}}</text>
									<text class="jpm-jiapu-price">已交{{item.price}}元</text>
								</view>
								<text class="jpm-jiapu-code">家谱号：{{item.coding}}</text>
								<view class="jpm-jiapu-xiupushi-view">
									<text class="jpm-jiapu-xiupushi-name" v-if="item.rname">修谱师：{{item.rname}} {{item.rmobile}}</text>
									<text class="jpm-jiapu-xiupushi-fenpei" v-else @click="fenpeiXPS"  :data-index="item">分配修谱师</text>
								</view>
								<text class="jpm-jiapu-time">开通时间：{{item.createtime}}</text>
							</view>
							<!-- 修谱师管理 -->
							<view v-if="tabIndex==2" class="xpsm-view" v-for="(item , index) in xpsList" :key="index">
								<view class="xpsm-name-view">
									<text class="xpsm-name">{{item.nickname+item.nickcname}} {{item.mobile}}</text>
									<text class="xpsm-detail" @click="goXPSDetail" :data-index="item">查看明细</text>
								</view>
								<view class="xpsm-time-view">
									<text class="xpsm-time">加入时间：{{item.createtime.split(" ")[0]}}</text>
									<text class="xpsm-price">营业额：{{item.price}}</text>
								</view>
							</view>
							<view style="width: 100%;height: 30rpx;"></view>
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
		<openMeritListPop :isShow="isShowOpenMeritListPop" :dataSource="jiapuguanData.id"  @returnOpenMeritDialog="returnOpenMeritDialog"/>
	</view>
</template>

<script>
	import request from '../../pages/index/request.js';
	import openMeritListPop from '../../components/open-merit-list-pop/open-merit-list-pop.vue';
	export default {
		components: {
			openMeritListPop
		},
		data() {
			return {
				isShowOpenMeritListPop:false,
				tabIndex: 0,
				userData:{},
				jiapuguanList: [],
				jiapuguanData: {},
				yyePage: 1,
				yyeList: [],
				jpmPage: 1,
				jpmList: [],
				xpsPage: 1,
				xpsList: [],
			}
		},
		methods: {
			onUnload:function(){
				uni.$off("refrash-list")
			},
			onLoad: function(options) {
				// 监听事件
				uni.$on('refrash-list',this.refrashList)
				this.getJpmuseumList()
				this.getUserData()
			},
			refrashList:function(e){
				if(e){
					this.getJpmuseumList(e.id)
				}else{
					this.getJpmuseumList(this.jiapuguanData.id)
				}
			},
			onShow: function() {
				this.share.url = '../../pages/tabBar/home/index?appInviteId=' + this.appUtil.getAppInviteId()
				this.share.shareType = 1
			},
			tabClick: function(e) {
				this.tabIndex = e.target.dataset.current || e.currentTarget.dataset.current;
			},
			ontabchange: function(e) {
				this.tabIndex = e.target.current || e.detail.current;
			},
			/** scroll-view到底部加载更多 */
			onreachBottom: function() {
				switch (this.tabIndex) {
					case 0:
						if(this.yyeList.length%20==0){
							this.yyePage = this.yyePage + 1
							this.getJpmuseumTurnoverList(this.jiapuguanData.id)
						}
						break
					case 1:
						if(this.jpmList.length%20==0){
							this.jpmPage = this.jpmPage + 1
							this.getJpmuseumTreeList(this.jiapuguanData.id)
						}
						break
					case 2:
						if(this.xpsList.length%20==0){
							this.xpsPage = this.xpsPage + 1
							this.getJpmuseumXpsList(this.jiapuguanData.id)
						}
						break
				}
			},
			getUserData: function() {
				var that = this
				request.post("api/user/index", {}).then(data => {
					that.userData = data;
				})
			},
			//家谱馆列表
			getJpmuseumList: function(e) {
				var that = this
				request.post("api/common/GetJpmuseumList", {}).then(data => {
					that.jiapuguanList = data
					if (e) {
						for (var i = 0; i < that.jiapuguanList.length; i++) {
							if(that.jiapuguanList[i].id==e){
								that.jiapuguanData = that.jiapuguanList[i]
							}
						}
					} else {
						that.jiapuguanData = that.jiapuguanList[0]
					}
					uni.setNavigationBarTitle({
						title:that.jiapuguanData.name
					})
					that.yyePage=1
					that.getJpmuseumTurnoverList(that.jiapuguanData.id)
					that.jpmPage=1
					that.getJpmuseumTreeList(that.jiapuguanData.id)
					this.xpsPage=1
					that.getJpmuseumXpsList(that.jiapuguanData.id)
				})
			},
			getJpmuseumTurnoverList:function(jpmuseumid){
				var that = this
				request.post("api/common/GetJpmuseumTurnoverList", {
					page:this.yyePage,
					jpmuseumid:jpmuseumid,
				}).then(data => {
					if(this.yyePage==1){
						that.yyeList=data
					}else{
						for (var i = 0; i < data.length; i++) {
							that.yyeList.push(data[i]) 
						}
					}
				})
			},
			getJpmuseumTreeList:function(jpmuseumid){
				var that = this
				request.post("api/common/GetJpmuseumTreeList", {
					page:this.jpmPage,
					jpmuseumid:jpmuseumid,
				}).then(data => {
					if(this.jpmPage==1){
						that.jpmList=data
					}else{
						for (var i = 0; i < data.length; i++) {
							that.jpmList.push(data[i]) 
						}
					}
				})
			},
			getJpmuseumXpsList:function(jpmuseumid){
				var that = this
				request.post("api/common/GetJpmuseumXpsList", {
					page:this.xpsPage,
					jpmuseumid:jpmuseumid,
				}).then(data => {
					if(this.xpsPage==1){
						that.xpsList=data
					}else{
						for (var i = 0; i < data.length; i++) {
							that.xpsList.push(data[i]) 
						}
					}
				})
			},
			changeGM:function(){
				uni.navigateTo({
					url:"../genealogy-museum-list/index?jpmuseumid="+this.jiapuguanData.id,
				})
			},
			goXPSDetail:function(item) {
				var data=item.currentTarget.dataset.index
				uni.navigateTo({
					url:"../genealogy-museum-xps/index?userPQD="+data.PQD,
				})
			},
			fenpeiXPS:function(item){
				var data=item.currentTarget.dataset.index
				uni.navigateTo({
					url:"../genealogy-museum-xps-list/index?jpmuseumid="+this.jiapuguanData.id+"&jpcode="+data.coding,
				})
			},
			fenpeiXPS1:function(item){
				var data=item.currentTarget.dataset.index
				uni.navigateTo({
					url:"../genealogy-museum-xps-list/index?jpmuseumid="+this.jiapuguanData.id+"&jpcode="+data.treecode,
				})
			},
			openMerit:function(){
				this.isShowOpenMeritListPop=true
			},
			returnOpenMeritDialog:function(e){
				this.isShowOpenMeritListPop=e.isclose
				if(e.tag=='sure'){
					this.getJpmuseumList(this.jiapuguanData.id)
				}
			},
		}
	}
</script>

<style>
	@import "index.css";
</style>
